Imports Pacientes
Imports System.Data.SqlClient
Imports System.Collections

Public Class frmTurnos
    Private Matricula As Integer
    Dim idTipoEst As Integer = 0
    Dim fecha As String = ""
    Dim mat As Integer = 0
    Dim profes As String = ""

    Dim ban As Integer = 0
    Private tur As Turnos = Nothing
    Private datos As DataSet = Nothing
    Private prof As Profesional = Nothing
    Private TurnoPac As TurnosxPaciente = Nothing
    Public Property TurPac() As TurnosxPaciente
        Get
            Return TurnoPac
        End Get
        Set(ByVal value As TurnosxPaciente)
            TurnoPac = value
        End Set
    End Property
    

    Private Sub Turnos_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        Close()
    End Sub

    Private Sub Turnos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim datos As DataSet = Nothing
        'Dim turnos As Turnos = New Turnos()
        Me.grTurnos.AutoGenerateColumns = False
        CargarCombos()
        dtFecha.Value = TurnosCORREGIDO.dtpFechaTur.Value
        cboProf.Text = TurnosCORREGIDO.lblProfTurno.Text ' txtProfTurno.Text

        'DATOS PROFESIONAL
        Dim obj As Profesional = New Profesional
        Dim prof As Profesional = Nothing
        prof = New Profesional()
        profes = cboProf.Text
        With Me.tur
            If obj.BuscarProf(profes, conexion) Then
                mat = obj.MatriculaProf
                'buscar agenda prof
                datos = prof.BuscarAgenda(mat, conexion)
                'mostrar datos
                grAgendaProf.AutoGenerateColumns = False
                grAgendaProf.DataSource = datos
                grAgendaProf.DataMember = "agendaprofesional"
                
            End If

        End With



    End Sub

    Private Sub CargarCombos()
        Dim datos As DataSet = Nothing

        prof = New Profesional()
        datos = prof.BuscarDatos(conexion)
        Me.cboProf.DataSource = datos.Tables(0)
        Me.cboProf.DisplayMember = "apenom"
        Me.cboProf.ValueMember = "matricula"
        ban = 0
    End Sub

    Private Sub cmdSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Close()
    End Sub

    Private Sub grTurnos_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grTurnos.CellClick
        If grTurnos.Columns(e.ColumnIndex).Name = "colCheck" Then
            Dim idhora As Integer
            Dim fecha As String
            Dim objProfesional As Profesional = New Profesional
            Dim TurnoPac As TurnosxPaciente = New TurnosxPaciente
            Dim celda As DataGridViewButtonCell = _
                CType(Me.grTurnos.Rows(e.RowIndex).Cells("colCheck"), DataGridViewButtonCell)

            idhora = Integer.Parse(grTurnos.Rows(e.RowIndex).Cells("idhora").Value) 'da error dice que es nulo
            fecha = dtFecha.Value

            CType(Me.Owner, TurnosCORREGIDO).FechaTurnos = dtFecha.Value
            CType(Me.Owner, TurnosCORREGIDO).ProfTur = cboProf.Text
            objProfesional.Buscar(Me.cboProf.SelectedValue(), conexion)
            CType(Me.Owner, TurnosCORREGIDO).profesionalObj = objProfesional

            CType(Me.Owner, TurnosCORREGIDO).TurnosPac = New Turnos
            CType(Me.Owner, TurnosCORREGIDO).TurnosPac.Buscar(idhora, conexion)
            Close()

        End If
    End Sub

    Private Sub CargarTurnos(ByVal idHora, ByVal hora)
        Dim datos As DataSet = Nothing
        Dim turnos As Turnos = New Turnos()

        profes = cboProf.Text
        tur = New Turnos()
        datos = tur.BuscarDatos(fecha, mat, conexion)

        grTurnos.AutoGenerateColumns = False
        grTurnos.DataSource = datos
        grTurnos.DataMember = "TurnosAsignados"

    End Sub


    ''VER AQUI COORRECION DEL CLICK DEL COMBO PARA QUE ME DE LA MATRICULA DEL PROFESIONAL
    Private Sub cboProf_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboProf.SelectedIndexChanged
        Dim datos As DataSet = Nothing

        If Me.cboProf.SelectedValue.GetType().ToString.CompareTo("System.Decimal") = 0 Then
            mat = Integer.Parse(cboProf.SelectedValue)
        Else
            mat = Integer.Parse(CType(cboProf.SelectedValue, DataRowView).Item(0))
        End If
       
        fecha = Me.dtFecha.Value.ToString("dd/MM/yyyy")
        Dim obj As Profesional = New Profesional
        Dim prof As Profesional = Nothing
        prof = New Profesional()
        profes = cboProf.Text
        With Me.tur
            If obj.BuscarProf(profes, conexion) Then
                mat = obj.MatriculaProf
                'buscar agenda prof
                datos = prof.BuscarAgenda(mat, conexion)
                'mostrar datos
                grAgendaProf.AutoGenerateColumns = False
                grAgendaProf.DataSource = datos
                grAgendaProf.DataMember = "agendaprofesional"
            End If
        End With


        'CargarTurnos(fecha, mat)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As frmCalcularMontos = New frmCalcularMontos()
        frm.ShowDialog(Me)
        frm.Dispose()
    End Sub

    Private Sub grAgendaProf_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grAgendaProf.CellClick
        'cargar turnos segun horarios de profesional
        CargarTurnos(fecha, mat)
    End Sub

    Private Sub grAgendaProf_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grAgendaProf.CellContentClick

    End Sub

    Private Sub grTurnos_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grTurnos.CellContentClick

    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub
End Class